var userinfo = null;
var check_id = '';
var check_no = '';
var ROWS_COUNT = 0;
$(document).ready(function(){
	var url = window.location;
	check_id= cw.common.getQueryString(url,"CHECKID");
	cw.common.getUserSession(getUserInfo);//查询用户
})
var getUserInfo = function(us){
	userinfo=us;
	queryTCheckInfo();
}

//查询盘点单
var queryTCheckInfo = function(){
	var url = cw.common.path + '/json?action=GET_T_CHECK_INFO_ACTION&ID='+check_id;
	$.post(url,{},function(data){
		if(data.success){
			var vobj=data.root.T_CHECK_INFO;
			if(vobj==null||vobj==''||vobj==undefined){
				alert("该盘点单不存在或已被删除");
				return;
			}
			else{
				var obj = data.root.T_CHECK_INFO.rs[0];
				$("#ID").val(check_id);
				$("#CHECK_NO").html(obj.CHECK_NO)
				$("#PERSON").html(obj.PERSON_NAME);
				$("#CHANGE_BEGIN_DATE").html(cw.common.toChar(obj.CHANGE_BEGIN_DATE,'yyyy-mm-dd'));
				$("#CHANGE_END_DATE").html(cw.common.toChar(obj.CHANGE_END_DATE,'yyyy-mm-dd'))
				$("#CHENG_BEFULLOF").html(obj.CHENG_BEFULLOF);
				$("#CHENG_LOSE").html(obj.CHENG_LOSE);
				$("#BEFULLOF_LOSE").html(obj.BEFULLOF_LOSE);
				var status = obj.CHAGE_STATUS;
				if(status=='1')status="盘点中";else status="结束";
				$("#CHAGE_STATUS").html(status);
				check_no = obj.CHECK_NO;
				QUERY_T_CHECK_INFO_DETAILBY_PAGER_ACTION();
			}
		}
		else{
			alert(data.errors.errmsg);
		}
	},'json');
}

//资产详细信息
var QUERY_T_CHECK_INFO_DETAILBY_PAGER_ACTION = function(){
	ROWS_COUNT=0;
	var barcode = $('#BARCODE').val();
	if(barcode==undefined)barcode='';
	var url = cw.common.path + '/json?action=QUERY_T_CHECK_INFO_DETAILBY_PAGER_ACTION';
	url += "&CHECK_NO="+check_no;
	url += "&BARCODE="+barcode;
	var xmlname = "T_CHECK_INFO_DETAIL";
	var pagePanel='#T_CHECK_INFO_DETAIL_pager';
	var result='#T_CHECK_INFO_DETAIL_LIST';
	var pageSize=10;
	var defaultHtml='<li><em style="text-align: center;width:100%">没有搜索到您要查询的数据...</em></li>';
	cw.common.changePage(url,pageSize,xmlname,result,fn_QUERY_T_CHECK_INFO_DETAILBY_PAGER_ACTION,pagePanel,defaultHtml);
}
var fn_QUERY_T_CHECK_INFO_DETAILBY_PAGER_ACTION = function(obj,result,i){
	ROWS_COUNT++;
	var str='<li id="bar_'+obj.ID+'-'+obj.BARCODE+'">';
	var status = obj.IS_CHECK;
	var statusLink = '';
	if(status=='0'){
		status="未盘点";
		statusLink='<a href="javascript:chekDetial(\''+obj.ID+'-'+obj.BARCODE+'\')">盘点</a>';
	}else {
		status="已盘点";
		statusLink='<a href="javascript:unchekDetial(\''+obj.ID+'-'+obj.BARCODE+'\')">去除盘点</a>';
		}
	str+='<em style="width: 9%; text-align: center;">'+obj.BARCODE+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+obj.FIXED_ASSETS_NAME+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+obj.NCNO+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+obj.DEPARTMENT_NAME+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+obj.STORED_IN+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+obj.WITH_MANANGER+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+status+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+obj.ADJUST_STATUS_NAME+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+cw.common.toChar(obj.CHECK_DATE,'yyyy-mm-dd')+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+obj.CHECK_PERSON+'</em>';
	str+='</li>';
	$(result).append(str);
}